/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/rng/fortuna/fnaEntropySource.cpp,v 1.4 2003/11/21 16:12:58 itsme Exp $
 *
 *
 * Design of the PRNG is literally taken from 'Practical Cryptography', by Niels Ferguson, and Bruce Schneier.
 *
 * This class is subclassed for all the implemented entropy sources:
 *   - audioinput
 *   - cryptoapi
 *
 */


#include <windows.h>

#include "fnaEntropySource.h"
#include "debug.h"

EntropySource::EntropySource()
{
    m_event= CreateEvent(NULL, TRUE, FALSE, NULL);
    m_poolnr= 0;
}

EntropySource::~EntropySource()
{
    CloseHandle(m_event);
}
void EntropySource::SetParams(Accumulator::sourcenumber_t nr, Accumulator& prng)
{
    m_sourcenr= nr;
    m_accu= &prng;
}
HANDLE EntropySource::GetEvent() const
{
    return m_event;
}
void EntropySource::AddRandom(const ByteVector& data)
{
    m_accu->AddRandomEvent(m_sourcenr, NextPoolNr(), data);
}
Accumulator::poolnumber_t EntropySource::NextPoolNr()
{
    int pool= m_poolnr++;
    if (m_poolnr>=Accumulator::NROFPOOLS)
        m_poolnr= 0;

    return pool;
}

void EntropySource::SignalNewData()
{
    SetEvent(m_event);
}
